package com.kitty.game.player.facade;

import com.kitty.game.role.model.Role;
import com.kitty.game.player.PlayerService;
import com.kitty.listener.EventType;
import com.kitty.listener.annotation.EventHandler;
import com.kitty.listener.event.LoginEvent;
import com.kitty.listener.event.LogoutEvent;
import com.kitty.listener.event.RoleLevelUpEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class PlayController {

    @Autowired
    PlayerService playerService;

    /**处理角色升级事件*/
    @EventHandler(EventType.ROLE_LEVEL_UP)
    public void handleRoleLevelUpEvent(RoleLevelUpEvent roleLevelUpEvent) {
        Role role = roleLevelUpEvent.getRole();
        playerService.updateRoleLevel(role);
    }

    /**处理玩家登录事件*/
    @EventHandler(EventType.LOGIN)
    public void handleLoginEvent(LoginEvent loginEvent) {
        Role role = loginEvent.getRole();
        playerService.updateRoleEnterTime(role);
    }

    /**下线时更新下PlayerProfile的数据，方便不在线时可以通过PlayerProfile拿玩家的数据*/
    @EventHandler(EventType.LOGOUT)
    public void handleLogoutEvent(LogoutEvent logoutEvent) {
        Role role = logoutEvent.getRole();
        playerService.updatePlayerProfile(role);
    }
}
